/*
 * Copyright (C) 2015 The Android  Source Project 
 *
 * Licensed under the Apache License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 *
 *      http://www.ido517.com
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package utils.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.ygk.bluepath.R;
import com.ygk.bluepath.core.BActivity;


/**
 * @Description TODO
 * @author 李文伟
 * @email lvsedewenzi@163.com
 * @date 2015-11-23 上午11:21:38
 */
public class DialogWithOutView extends Dialog {
	private View view;
	private Window window;
	private boolean isFinish = false;
	private BActivity act;

	/**
	 * @param context
	 */
	public DialogWithOutView(Context context) {
		super(context);
		// TODO Auto-gesnerated constructor stub
		init();
	}

	/**
	 * @param context
	 */
	public DialogWithOutView(Context context, int style) {
		super(context, style);
		// TODO Auto-generated constructor stub
		init();
	}

	/**
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 */
	private void init() {
		// TODO Auto-generated method stub
		window = getWindow();
		setCanceledOnTouchOutside(true);
	}

	public void setBgTransparent() {
		// TODO Auto-generated method stub
		window.setBackgroundDrawableResource(R.color.transparent); // 设置对话框背景为透明
	}

	public void setBgColor(int color) {
		// TODO Auto-generated method stub
		window.setBackgroundDrawableResource(color); // 设置对话框背景为透明
	}

	public void setGravityBottom() {
		// TODO Auto-generated method stub
		window.setGravity(Gravity.BOTTOM);
	}

	public void setWindowAnimations(int resId) {
		// TODO Auto-generated method stub
		window.setWindowAnimations(resId);
	}

	/**
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 */
	public View inflaterView(int ViewID, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		view = getLayoutInflater().inflate(ViewID, viewGroup);
		setContentView(view);
		return view;

	}

	public void setView(View view) {
		// TODO Auto-generated method stub
		setContentView(view);
		this.view = view;

	}

	/**
	 * @Description: TODO
	 * @param
	 * @return void
	 * @throws
	 */
	public void setDismissFinish(BActivity act, boolean isFinish) {
		// TODO Auto-generated method stub
		this.isFinish = isFinish;
		this.act = act;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Dialog#dismiss()
	 */
	@Override
	public void dismiss() {
		// TODO Auto-generated method stub
		super.dismiss();
		if (isFinish) {
			if (act != null) {
				act.finish();
			}
		}
	}
}
